<?php

/**
 * banda actions.
 *
 * @package    blackDrums
 * @subpackage banda
 * @author     your name here
 */
class bandaActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->Bandas = BandaPeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->Banda = BandaPeer::retrieveByPk($request->getParameter('idbanda'));
    $this->IntegrantesBanda = ClienteNaturalPeer::integrantesBanda($request->getParameter('idbanda'));
    $this->forward404Unless($this->Banda);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new BandaForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new BandaForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($Banda = BandaPeer::retrieveByPk($request->getParameter('idbanda')), sprintf('Object Banda does not exist (%s).', $request->getParameter('idbanda')));
    $this->form = new BandaForm($Banda);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($Banda = BandaPeer::retrieveByPk($request->getParameter('idbanda')), sprintf('Object Banda does not exist (%s).', $request->getParameter('idbanda')));
    $this->form = new BandaForm($Banda);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {

    $this->forward404Unless($Banda = BandaPeer::retrieveByPk($request->getParameter('idbanda')), sprintf('Object Banda does not exist (%s).', $request->getParameter('idbanda')));
    $Banda->delete();

    $this->redirect('banda/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $Banda = $form->save();

      $this->redirect('banda/index');
    }
  }
}
